package com.yonyou.brigade.order_center.service.impl;

import com.yonyou.brigade.order_center.model.BriFlightInfo;
import com.yonyou.brigade.order_center.model.BriFlightOrder;
import com.yonyou.brigade.order_center.model.BriFlightPassenger;
import com.yonyou.brigade.order_center.model.api.BriFlightOrderInfoAPIDTO;
import com.yonyou.brigade.order_center.service.IBriFlightInfoService;
import com.yonyou.brigade.order_center.service.IBriFlightOrderInfoAPIService;
import com.yonyou.brigade.order_center.service.IBriFlightOrderService;
import com.yonyou.brigade.order_center.service.IBriFlightPassengerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class BriFlightOrderInfoAPIServiceImpl implements IBriFlightOrderInfoAPIService{

    @Autowired
    @Qualifier("briFlightOrderServiceImpl")
    private IBriFlightOrderService briFlightOrderService;

    @Autowired
    @Qualifier("briFlightInfoServiceImpl")
    private IBriFlightInfoService briFlightInfoService;

    @Autowired
    @Qualifier("briFlightPassengerServiceImpl")
    private IBriFlightPassengerService briFlightPassengerService;



    public List<BriFlightOrderInfoAPIDTO> getBriFlightOrderAPIDTOS(Map params){
        List<BriFlightOrderInfoAPIDTO> briFlightOrderInfoAPIDTOs = new ArrayList<>();
        List<BriFlightOrder> briFlightOrders = briFlightOrderService.getBriFlightOrder(params);
        for (BriFlightOrder briFlightOrder : briFlightOrders){
            BriFlightOrderInfoAPIDTO briFlightOrderInfoAPIDTO = new BriFlightOrderInfoAPIDTO();
            briFlightOrderInfoAPIDTO.setBriFlightOrder(briFlightOrder);
            List<BriFlightInfo> briFlightInfos = briFlightInfoService.getBriFlightInfo(briFlightOrder.getOrderNo());
            List<BriFlightPassenger> briFlightPassengers = briFlightPassengerService.getBriFlightPassenger(briFlightOrder.getOrderNo());
            briFlightOrderInfoAPIDTO.setBriFlightInfos(briFlightInfos);
            briFlightOrderInfoAPIDTO.setBriFlightPassengers(briFlightPassengers);
            briFlightOrderInfoAPIDTOs.add(briFlightOrderInfoAPIDTO);
        }
        return briFlightOrderInfoAPIDTOs;
    }
}
